package com.admin.his.user.service.impl;

import com.admin.his.common.dao.UserEntityDao;
import com.admin.his.common.entity.UserEntity;
import com.admin.his.common.exception.ThisSystemException;
import com.admin.his.user.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Objects;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserEntityDao dao;

    @Override
    public UserEntity login(String account, String password) throws Exception {

        if (account==null){
            throw new ThisSystemException("account can't be null","账号未填写");
        }
        if (password==null){
            throw new ThisSystemException("password can't be null","密码未填写");
        }
       UserEntity user=dao.selectByAccount(account);
       if (user==null){
           throw new ThisSystemException("account not exists","账号不存在");
       }
       if (Objects.equals(user.getPassword(),password)){
           return user;
       }else{
           throw new ThisSystemException("password was wrong","密码错误");
       }

    }
}
